package io.babystar.modules.business.controller;

import io.babystar.common.utils.PageUtils;
import io.babystar.common.utils.R;
import io.babystar.modules.business.entity.BaseMemberCardEntity;
import io.babystar.modules.business.service.BaseMemberCardService;
import io.babystar.modules.business.service.BaseVipService;
import io.babystar.modules.sys.controller.AbstractController;
import io.babystar.modules.sys.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 *
 *
 * @author jeson
 * @email 574197743@qq.com
 * @date 2021-03-23 20:03:34
 */
@RestController
@RequestMapping("business/basemembercard")
public class BaseMemberCardController extends AbstractController {
    @Autowired
    private BaseMemberCardService baseMemberCardService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:basemembercard:list")
    public R list(@RequestParam Map<String, Object> params){
        SysUserEntity user = this.getUser();
        params.put("business_id",user.getBusinessId());
        PageUtils page = baseMemberCardService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("business:basemembercard:info")
    public R info(@PathVariable("id") Long id){
        BaseMemberCardEntity baseMemberCard = baseMemberCardService.getById(id);

        return R.ok().put("baseMemberCard", baseMemberCard);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("business:basemembercard:save")
    public R save(@RequestBody BaseMemberCardEntity baseMemberCard){
        SysUserEntity user = this.getUser();
        baseMemberCard.setOrganizeId(Integer.parseInt(user.getBusinessId()+""));
        baseMemberCardService.save(baseMemberCard);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("business:basemembercard:update")
    public R update(@RequestBody BaseMemberCardEntity baseMemberCard){
        baseMemberCardService.updateById(baseMemberCard);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("business:basemembercard:delete")
    public R delete(@RequestBody Long[] ids){
        baseMemberCardService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询会员卡状态
     */
    @RequestMapping("/getMemberCard")
    public List<BaseMemberCardEntity> getMemberCard(@RequestParam Map<String, String> params){
        SysUserEntity user = this.getUser();
        List<BaseMemberCardEntity> list = baseMemberCardService.getMemberCard(Integer.parseInt(user.getBusinessId()+""));
        return list;
    }

}
